/*-------------------------------------------------------------------------
 * Helper.cs
 *
 * This file is part of the PGORM project.
 * http://pgorm.googlecode.com/
 *
 * Copyright (c) 2002-2009, TrueSoftware B.V.
 *
 * IDENTIFICATION
 * 
 *  $Id: Helper.cs 41 2009-04-05 12:28:14Z gevikb $
 * 	$HeadURL: http://pgorm.googlecode.com/svn/tags/Release-0.10.4/PGORM/Core/Helper.cs $
 * 	
 *-------------------------------------------------------------------------
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PGORM
{
    public class Helper
    {
        public static string EscapeString(string data)
        {
            return data.Replace("\\","\\\\").Replace("\"", "\\\"");
        }

        public static string RemovePrefix(string source, List<string> items)
        {
            foreach (string prefix in items)
                if (source.IndexOf(prefix) == 0)
                {
                    source= source.Replace(prefix, "");
                    return source;
                }
            return source;
        }

        private static List<string> p_ReservedWords = new List<string>();
        
        public static bool IsReservedWord(string word)
        {
            // load if first time
            if(p_ReservedWords.Count == 0)
                p_ReservedWords.AddRange(CodeTemplates.ReservedWords.Split(new char[] { '\r','\n' }, StringSplitOptions.RemoveEmptyEntries));
            return p_ReservedWords.Contains(word);
        }
    }
}